package com.xx.happychatboot.middleware.netty.factory.websocket;

import com.xx.happychatboot.middleware.netty.strategy.websocket.AbstractWebsocketStrategy;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * websocket工厂
 */
@Component
public class WebSocketFactory {
    //策略实现类集合
    private static final Map<Integer, AbstractWebsocketStrategy> STRATEGY_MAP = new HashMap<>();

    //注册方法
    public static void register(Integer code, AbstractWebsocketStrategy websocketStrategy) {
        STRATEGY_MAP.put(code, websocketStrategy);
    }

    //获取对应的策略方法
    public static AbstractWebsocketStrategy getStrategyNoNull(Integer code) {
        return STRATEGY_MAP.get(code);
    }
}
